﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RanchBuddy.Core.DataAccess.Impl;
using RanchBuddy.Core.Domain;
using RanchBuddy.Core.Domain.Impl;
using RanchBuddy.Core.Services;
using RanchBuddy.Core.Services.Impl;
using Microsoft.Web.Mvc;
using StructureMap;

namespace RanchBuddy.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult WhatIsYourZipCode(string url)
        {
            ViewData["url"] = url;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult WhatIsYourZipCode(string Zipcode, string url)
        {
            if(!string.IsNullOrEmpty(Zipcode) && Zipcode.Length == 5)
            {
                ObjectFactory.GetInstance<IWebContext>().Zipcode = Zipcode;
                Response.Redirect(ConfigurationService.GetRoot() + url);
            }
            return View();
        }

        public ActionResult Index()
        {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult ContactUs()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ContactUs(string Email, string FirstName, 
            string LastName, string Phone, string Subject, string Body)
        {
            EmailService.SendContactUsEmail(Email, Subject, FirstName, LastName, Body, Phone);
            return RedirectToAction("ContactUsSuccess");
        }

        public ActionResult ContactUsSuccess()
        {
            return View();
        }

        public ActionResult MemberAgreement()
        {
            return View();
        }

        public ActionResult PrivacyPolicy()
        {
            return View();
        }
        public ActionResult Help(bool partial, int HelpID)
        {
            if (partial)
            {
                if (HelpID > 0)
                {
                    HelpMessage h = HelpMessageService.GetHelpMessageByID(HelpID);
                    if (h != null)
                    {
                        ViewData["HelpMessageID"] = h.HelpMessageID;
                        ViewData["HelpMessage"] = h.Body;
                    }
                    else
                    {
                        ViewData["HelpMessageID"] = 0;
                        ViewData["HelpMessage"] = "There was an error loading the requested help message!";
                    }
                }
                
                return View("_Help", ViewData);
            }
            else
                return View("Help", ViewData);
        }
    }
}
